package com.geek.gkmember.biz.facade;

import com.geek.gkmember.facade.login.LoginFacade;
import com.geek.gkmember.facade.login.bean.LoginByAccountPwdReq;
import com.geek.gkmember.facade.login.bean.LoginByAccountPwdResp;
import com.geek.gkmember.util.hash.HashUtils;
import com.geek.gkmember.util.id.UuidUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.Date;

/**
 * <h1>登录服务 Facade 实现类。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2023/10/15 16:52
 */
@DubboService
public class LoginFacadeImpl implements LoginFacade {

    @Override
    public LoginByAccountPwdResp loginByAccountPwd(LoginByAccountPwdReq req) {
        // TODO 完全模拟假数据返回

        LoginByAccountPwdResp resp = new LoginByAccountPwdResp();
        resp.setRefreshToken(UuidUtils.getUuid());
        resp.setAccessToken(UuidUtils.getUuid());
        resp.setExpireTimeMillis(DateUtils.addMinutes(new Date(), 1).getTime());

        resp.setUserId(String.join("_", "UID", req.getAccount()));
        resp.setUserName(String.join("_", "UNAME", req.getAccount()));

        resp.setBucket(String.valueOf(HashUtils.hash(resp.getUserId())));

        return resp;
    }
}